home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1865 / 1865.xpi / chrome / adblockplus.jar / content / ui / tip_subscriptions.js < prev    next >
Text File  |  2010-01-07  |  5KB  |  165 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Adblock Plus.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Wladimir Palant.
  18.  * Portions created by the Initial Developer are Copyright (C) 2006-2009
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * ***** END LICENSE BLOCK ***** */
  24.  
  25. let autoAdd;
  26. let result;
  27.  
  28. let adblockID = "{34274bf4-1d97-a289-e984-17e546307e4f}";
  29. let filtersetG = "filtersetg@updater";
  30.  
  31. function init()
  32. {
  33.     autoAdd = !("arguments" in window && window.arguments && window.arguments.length);
  34.     result = (autoAdd ? {disabled: false, external: false, autoDownload: true} : window.arguments[0]);
  35.     document.getElementById("description-par1").hidden = !autoAdd;
  36.  
  37.     if (isExtensionActive(adblockID))
  38.         document.getElementById("adblock-warning").hidden = false;
  39.  
  40.     if (isExtensionActive(filtersetG))
  41.         document.getElementById("filtersetg-warning").hidden = false;
  42.  
  43.     if ("Filterset.G" in filterStorage.knownSubscriptions &&
  44.             !filterStorage.knownSubscriptions["Filterset.G"].disabled)
  45.     {
  46.         document.getElementById("filtersetg-warning").hidden = false;
  47.     }
  48.  
  49.     document.getElementById("subscriptions").selectedIndex = 0;
  50. }
  51.  
  52. function addSubscriptions() {
  53.     var group = document.getElementById("subscriptions");
  54.     var selected = group.selectedItem;
  55.     if (!selected)
  56.         return;
  57.  
  58.     result.url = selected.getAttribute("_url");
  59.     result.title = selected.getAttribute("_title");
  60.     result.autoDownload = true;
  61.     result.disabled = false;
  62.  
  63.     if (autoAdd)
  64.         abp.addSubscription(result.url, result.title, result.autoDownload, result.disabled);
  65. }
  66.  
  67. function addOther() {
  68.     openDialog("subscription.xul", "_blank", "chrome,centerscreen,modal", null, result);
  69.     if ("url" in result)
  70.     {
  71.         if (autoAdd)
  72.             abp.addSubscription(result.url, result.title, result.autoDownload, result.disabled);
  73.         window.close();
  74.     }
  75. }
  76.  
  77. function handleKeyPress(e) {
  78.     switch (e.keyCode) {
  79.         case e.DOM_VK_PAGE_UP:
  80.         case e.DOM_VK_PAGE_DOWN:
  81.         case e.DOM_VK_END:
  82.         case e.DOM_VK_HOME:
  83.         case e.DOM_VK_LEFT:
  84.         case e.DOM_VK_RIGHT:
  85.         case e.DOM_VK_UP:
  86.         case e.DOM_VK_DOWN:
  87.             return false;
  88.     }
  89.     return true;
  90. }
  91.  
  92. function handleCommand(event)
  93. {
  94.     let scrollBox = document.getElementById("subscriptionsScrollbox")
  95.                                                     .boxObject
  96.                                                     .QueryInterface(Ci.nsIScrollBoxObject);
  97.     scrollBox.ensureElementIsVisible(event.target);
  98.     scrollBox.ensureElementIsVisible(event.target.nextSibling);
  99. }
  100.  
  101. function uninstallExtension(id)
  102. {
  103.     let extensionManager = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
  104.     if (extensionManager.getItemForID(id))
  105.     {
  106.         let location = extensionManager.getInstallLocation(id);
  107.         if (location && !location.canAccess)
  108.         {
  109.             // Cannot uninstall, need to disable
  110.             extensionManager.disableItem(id);
  111.         }
  112.         else
  113.         {
  114.             extensionManager.uninstallItem(id);
  115.         }
  116.     }
  117. }
  118.  
  119. function isExtensionActive(id)
  120. {
  121.     let extensionManager = Cc["@mozilla.org/extensions/manager;1"].getService(Ci.nsIExtensionManager);
  122.  
  123.     // First check whether the extension is installed
  124.     if (!extensionManager.getItemForID(id))
  125.         return false;
  126.  
  127.     let ds = extensionManager.datasource;
  128.     let rdfService = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
  129.     let source = rdfService.GetResource("urn:mozilla:item:" + id);
  130.  
  131.     // Check whether extension is disabled
  132.     let link = rdfService.GetResource("http://www.mozilla.org/2004/em-rdf#isDisabled");
  133.     let target = ds.GetTarget(source, link, true);
  134.     if (target instanceof Ci.nsIRDFLiteral && target.Value == "true")
  135.         return false;
  136.  
  137.     // Check whether an operation is pending for the extension
  138.     link = rdfService.GetResource("http://www.mozilla.org/2004/em-rdf#opType");
  139.     if (ds.GetTarget(source, link, false))
  140.         return false;
  141.  
  142.     return true;
  143. }
  144.  
  145. function uninstallAdblock()
  146. {
  147.     uninstallExtension(adblockID);
  148.     document.getElementById("adblock-warning").hidden = true;
  149. }
  150.  
  151. function uninstallFiltersetG()
  152. {
  153.     // Disable further updates
  154.     abp.denyFiltersetG = true;
  155.  
  156.     // Uninstall extension
  157.     uninstallExtension(filtersetG);
  158.  
  159.     // Remove filter subscription
  160.     if ("Filterset.G" in filterStorage.knownSubscriptions)
  161.         filterStorage.removeSubscription(filterStorage.knownSubscriptions["Filterset.G"]);
  162.  
  163.     document.getElementById("filtersetg-warning").hidden = true;
  164. }
  165.